import {
    BrowserRouter as Router,
    Routes,
    Route,
    Navigate,
} from "react-router-dom";
import "./App.css";
import Layout from "./components/Layout/layout";
import HomePage from "./pages/Home";
import CategoryPage from "./pages/Category";
import CartPage from "./pages/Cart";
import ProfilePage from "./pages/Profile";
import DetailPage from "./pages/ProductDetail";

function App() {
    // replace  让路由重定向时不产生历史记录
    return (
        <Router>
            <Routes>
                <Route path="/" element={<Layout />}>
                    {/* index 是默认首页的意思  */}
                    <Route index element={<HomePage />}></Route>
                    <Route path="category" element={<CategoryPage />}></Route>
                    <Route path="cart" element={<CartPage />}></Route>
                    <Route path="profile" element={<ProfilePage />}></Route>
                </Route>
                <Route path="/product/:id" element={<DetailPage />}></Route>
                <Route path="*" element={<Navigate to="/" />} replace></Route>
            </Routes>
        </Router>
    );
}

export default App;
